package org.jupiter.blog.api.http;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jupiter.blog.api.dto.PageResponseDto;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class JupiterResult<T> {

	private int code;

	private String message;

	private T data;

	public static <T> JupiterResult<T> success() {
		return new JupiterResult<>(200, "成功", null);
	}

	public static <T> JupiterResult<T> success(T data) {
		return new JupiterResult<>(200, "成功", data);
	}

	/**
	 * 返回分页结果
	 *
	 * @param records
	 * 		数据列表
	 * @param total
	 * 		总记录数
	 */
	public static <E> JupiterResult<PageResponseDto<E>> page(List<E> records, long total) {
		return new JupiterResult<>(200, "成功", new PageResponseDto<>(records, total));
	}

	public static <T> JupiterResult<T> fail(String message) {
		return new JupiterResult<>(500, message, null);
	}
}